package com.neteast.androidclient.contact.adapter;

import java.util.List;

import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;

public class ContactPageAdapter extends PagerAdapter{

	public List<View> mListViews;

	public ContactPageAdapter(List<View> mListViews) {
		this.mListViews = mListViews;
	}
	
	@Override
	public int getCount() {
		return mListViews.size();
	}

	@Override
	public boolean isViewFromObject(View arg0, Object arg1) {
		return arg0 == (arg1);
	}

	public View getItem(int position){
		return mListViews.get(position);
	}
	 /**
     * 从指定的position创建page
     *
     * @param collection ViewPager容器
     * @param position The page position to be instantiated.
     * @return 返回指定position的page，这里不需要是一个view，也可以是其他的视图容器.
     */
	@Override
	public Object instantiateItem(View collection, int position) {
		((ViewPager) collection).addView(mListViews.get(position),0);
		return mListViews.get(position);
	}

	 /**
     * 从指定的position销毁page
     * 参数同上
     */
	@Override
	public void destroyItem(View collection, int position, Object view) {
		((ViewPager) collection).removeView(mListViews.get(position));
	}
	
	 /**
     * Called when the a change in the shown pages has been completed.  At this
     * point you must ensure that all of the pages have actually been added or
     * removed from the container as appropriate.
     * @param container The containing View which is displaying this adapter's
     * page views.
     */
	@Override
	public void finishUpdate(View arg0) {}
	

	@Override
	public void restoreState(Parcelable arg0, ClassLoader arg1) {}

	@Override
	public Parcelable saveState() {
		return null;
	}

	@Override
	public void startUpdate(View arg0) {
		
	}
	
	public void addItem(View view){
		mListViews.add(view);
		notifyDataSetChanged();
	}
	
	
}
